﻿$(document).ready(function () {
	if (tinyMCE) {
		tinyMCE.init({
			theme: "advanced",
			mode: "specific_textareas",
			editor_selector: "tinymce",
			plugins: "paste,fullscreen,searchreplace,inlinepopups",
			paste_text_sticky: true,
			theme_advanced_toolbar_location: "top",
			theme_advanced_toolbar_align: "left",
			theme_advanced_buttons1: "search,replace,|,cut,copy,paste,|,undo,redo,|,link,unlink,charmap,emoticon,codeblock,|,bold,italic,|,numlist,bullist,formatselect,|,code,fullscreen",
			theme_advanced_buttons2: "",
			theme_advanced_buttons3: "",
			convert_urls: false,
			valid_elements: "*[*]",
			// shouldn't be needed due to the valid_elements setting, but TinyMCE would strip script.src without it.
			extended_valid_elements: "script[type|defer|src|language]",
			setup: function (ed) {
			    ed.onInit.add(function (ed, e) {
			        $(ed.getDoc()).children().find('head').append('<style type="text/css">html { overflow-y:auto; }</style>');
			        ed.pasteAsPlainText = true;
			    });
			}
		});
	}
	$('#txtName').friendurl({ id: 'txtNameOnUrl', divider: '-', transliterate: true });

	$('#nineseas-reader-content').bind('heightChanged', function () {
	    $('#edit-area').height($('#nineseas-reader-content').height() - 12 /*container's paddings */ * 2);
	});
});